<?php
/**
  *  Project name: KSSystem
  *  Created on: 08.12.2011
  *  Author: Kai R�der
  *
  *  
  */
if(isset($_POST['earmarkAdmin']))
{
    include_once("class/user/class.userCreate.php");
        
    // Check input data
    /*
     * ------------------------------------------------------------
     */
    
    if($_POST['vorname']) { $vorname = $_POST['vorname']; } 
    else { $errors[] = "Bitte geben Sie einen Vornamen an."; }
    
    if($_POST['name']) { $name = $_POST['name']; } 
    else { $errors[] = "Bitte geben Sie einen Nachnamen an."; }
    
    if($_POST['e-mail']) { $email = $_POST['e-mail']; } 
    else { $errors[] = "Bitte geben Sie eine E-Mail an."; }
    
    // set status and rights
    $status = STATUS_VORMERKEN;
    $rechte = RECHT_ADMIN_SCHREIBEN;
    
    // if no error occurred...
    if(count($errors) == 0)
    {
        // User create object
        $usr = new CCreateUser();
        
        // Emplyee Meta-Data
        $usr->setVorname($vorname);
        $usr->setName($name);
        $usr->setEmail($email);
        
        // Access and userstate
        $usr->setStatus($status);
        $usr->setRechte($rechte);
        
        // user who created row
        $usr->setBearbeiterId($_SESSION['userID']);
        
        // Create
        $usr->create();
        
        /*
         * Password per email senden
         */
        $header = 'From: contact@mrthomsen.de' . "\r\n" .
                   'Reply-To: contact@mrthomsen.de' . "\r\n" .
                   'X-Mailer: PHP/' . phpversion();
        
        $mailto = $email;
        $subject = "Ihnen wurde ein Zugang eingerichtet!";
        $mail_message = "Benutzername: " . $usr->getUsername() . "\r\n";
        $mail_message.= "Ihr neues Passwort lautet: " . $usr->getGeneratedPassword();
        
        mail($mailto, $subject, $mail_message, $header);
        
        header("LOCATION: index.php?page=administrator-view");
    }
    else 
    {
        echo '<h2>Fehler!</h2>';
        echo '<ul>';
        foreach($errors as $error)
        {
            echo '<li>' . $error . '</li>';
        } 
        echo '</ul>';
    }
}

// Embed form
include("module/administrator/administrator_form_edit.php");
?>

